using Assets.Scripts.GDK;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class ScoreBox : gdk_base_UI
	{
		public Text text;

		public Scrollbar sbar;

		public int maxScore = 1000;

		public int curScores;

		public GameObject[] stars;

		private int curStarLevel;

		public int curLeiJia = 10;

		public override void OnLoad()
		{
			gdk_game_manager.AddEventListener<int>(EventID.GAME_PLAY_START, OnGameStart);
			gdk_game_manager.AddEventListener(EventID.GAME_SHOOP_START, OnShotStart);
			gdk_game_manager.AddEventListener(EventID.GAME_SCORE_ADD, OnScoreAdd);
		}

		public override void UnLoad()
		{
			gdk_game_manager.RemoveEventListener<int>(EventID.GAME_PLAY_START, OnGameStart);
			gdk_game_manager.RemoveEventListener(EventID.GAME_SHOOP_START, OnShotStart);
			gdk_game_manager.RemoveEventListener(EventID.GAME_SCORE_ADD, OnScoreAdd);
		}

		public override void OnStart()
		{
			hideStars();
			showScore();
		}

		private void OnShotStart()
		{
			curLeiJia = 10;
		}

		private void OnGameStart(int level)
		{
			curScores = 0;
			showScore();
			showStar();
		}

		private void OnScoreAdd()
		{
			curScores += curLeiJia;
			curLeiJia += 10;
			showScore();
			showStar();
		}

		private void showScore()
		{
			text.text = curScores.ToString();
		}

		private void hideStars()
		{
			stars[0].SetActive(value: false);
			stars[1].SetActive(value: false);
			stars[2].SetActive(value: false);
		}

		private void showStar()
		{
			hideStars();
			int star = getStar(curScores);
			if (star > curStarLevel)
			{
				gdk_game_manager.PlaySound(AudioID.starup);
			}
			curStarLevel = star;
			switch (star)
			{
				case 3:
					stars[0].SetActive(value: true);
					stars[1].SetActive(value: true);
					stars[2].SetActive(value: true);
					break;
				case 2:
					stars[0].SetActive(value: true);
					stars[1].SetActive(value: true);
					break;
				case 1:
					stars[0].SetActive(value: true);
					break;
			}
			showBar(curScores, star);
			GDK.ModuleManger.Module<ScoreBoxModule>().setStarLevel(curStarLevel);
		}

		private int getStar(int score)
		{
			return GDK.ModuleManger.Module<EnemyBoxModule>().getStar(score);
		}

		private void showBar(int score, int star)
		{
			switch (star)
			{
				case 0:
					{
						maxScore = GDK.ModuleManger.Module<EnemyBoxModule>().getStarLevel(1);
						if (maxScore == 0)
						{
							sbar.size = 0.23f;
							break;
						}
						float num3 = (float)score * 1f / (float)maxScore;
						sbar.size = num3 * 0.23f;
						break;
					}
				case 1:
					{
						maxScore = GDK.ModuleManger.Module<EnemyBoxModule>().getStarLevel(2);
						int starLevel2 = GDK.ModuleManger.Module<EnemyBoxModule>().getStarLevel(1);
						float num2 = (float)(score - starLevel2) * 1f / (float)(maxScore - starLevel2);
						sbar.size = 0.62f * num2 + 0.23f;
						break;
					}
				case 2:
					{
						maxScore = GDK.ModuleManger.Module<EnemyBoxModule>().getStarLevel(3);
						int starLevel = GDK.ModuleManger.Module<EnemyBoxModule>().getStarLevel(2);
						float num = (float)(score - starLevel) * 1f / (float)(maxScore - starLevel);
						sbar.size = num * 0.15f + 0.85f;
						break;
					}
				default:
					sbar.size = 1f;
					break;
			}
		}
	}
}

